package com.example.design.创建型设计模式.建造者模式;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
//@Builder
public class Computer {
    private String brand;
    private String cpu;
    private int memory; // in GB
    private int storage; // in GB
    private String gpu;

    // 构造方法是私有的，防止直接创建对象
    private Computer(Builder builder) {
        this.brand = builder.brand;
        this.cpu = builder.cpu;
        this.memory = builder.memory;
        this.storage = builder.storage;
        this.gpu = builder.gpu;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "brand='" + brand + '\'' +
                ", cpu='" + cpu + '\'' +
                ", memory=" + memory +
                "GB, storage=" + storage +
                "GB, gpu='" + gpu + '\'' +
                '}';
    }

    // 内部 Builder 类
    public static class Builder {
        private String brand;
        private String cpu;
        private int memory; // in GB
        private int storage; // in GB
        private String gpu;

        public Builder setBrand(String brand) {
            this.brand = brand;
            return this;
        }

        public Builder setCpu(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder setMemory(int memory) {
            this.memory = memory;
            return this;
        }

        public Builder setStorage(int storage) {
            this.storage = storage;
            return this;
        }

        public Builder setGpu(String gpu) {
            this.gpu = gpu;
            return this;
        }

        // 静态方法返回 Builder 实例，也可以不要 create 方法，直接构建 Computer 对象
        public static Builder create() {
            return new Builder();
        }

        // 构建方法
        public Computer build() {
            return new Computer(this);
        }
    }
}